<!-- 社区借用 -->
<template>
  <div class="borrow">
    <myheader title="共享小区" rightBtn="添加可借用" @updataInfo="submitRecruit"></myheader>
    <!-- 搜索栏 -->
    <div class="serarch">
      <van-search v-model="searchValue" show-action placeholder="请输入搜索关键词" @search="onSearch" />
    </div>
    <ul v-if="!empty" class="borrow_Ul">
      <borro-record
        @getBorrow="handleCurrentChange"
        :pageSize="pageSize"
        :total="total"
        :borrow="borrow"
        :currentPage="currentPage"
        :active="1"
      ></borro-record>
    </ul>

    <van-empty v-else image="error" description="暂无此内容！" />
  </div>
</template>

<script>
import myheader from '../../../comon/myheader.vue'
import BorroRecord from '../../../comon/borroRecord.vue'
import formatDateTime from '../../../utils/data'
export default {
  components: {
    myheader,
    BorroRecord,
  },
  data() {
    return {
      headTitle: '',
      borrow: [],
      currentPage: 1,
      pageSize: 6,
      total: 1,
      empty: false,
      searchValue: '',
    }
  },

  created() {
    this.init()
  },
  methods: {
    //日期格式化
    formatDateTime(val) {
      return formatDateTime.formatDateTime5(val)
    },
    async init() {
      const res = await this.$axios.get(
        '/item/borrow/list?current=' +
          this.currentPage +
          '&size=' +
          this.pageSize
      )
      if (res.data.code == 200) {
        this.borrow = res.data.data.records
        this.total = res.data.data.total
        this.empty = false
      }
    },
    // 搜索
    async onSearch() {
      const res = await this.$axios.get(
        '/item/borrow/list?title=' + this.searchValue
      )
      if (res.data.code == 200) {
        this.borrow = res.data.data.records
        this.total = res.data.data.total
        this.pageCount = res.data.data.pages
        this.searchValue = ''
        if (res.data.data.total == 0) {
          this.empty = true
        } else {
          this.empty = false
        }
      }
    },
    // 添加借用物品
    submitRecruit() {
      this.$router.push('/addBorrow')
    },

    // 分页
    handleCurrentChange(currentPage) {
      this.currentPage = currentPage
      this.init()
    },
  },
}
</script>

<style scoped>
.borrow {
  margin-top: 46px;
  margin-bottom: 30px;
}
</style>
